package chapter04;

public class Java19_Object {
    public static void main(String[] args) {
        // TODO 单例模式
        // JVM默认提供的构造方法其实是公共的，无参的
        /*
            1.类的创建过程复杂
            2.类的对象消耗资源
         */
        //User19 user = new User19();
        User19 user = User19.getInstance();
        User19 user1 = User19.getInstance();
        User19 user2 = User19.getInstance();
        User19 user3 = User19.getInstance();
        User19 user4 = User19.getInstance();
        User19 user5 = User19.getInstance();

        System.out.println(user == user1);
        System.out.println(user3.equals(user4));

    }
}

class User19 {
    private static User19 user19 = null;
    private User19() {

    }
    public static User19 getInstance() {
        if (user19 == null) {
            user19 = new User19();
        }
        return user19;
    }
}
